/*
 * File:    SchedulerTimeContext.java
 * Created: 20-Oct-2006
 *
 * by Kenji Hollis <kenji@bitgatesoftware.com>
 * Released under the Creative Commons License version 2.5
 */

package com.bitgate.util.scheduler;

/**
 * This class is used to set the time in which a class is called in the <code>Scheduler</code>.  To exclude the value
 * from being used, use either a &quot;*&quot;, or <code>NO_TIMES</code>.  Range formats can be the following:
 * <p/>
 * <li> &quot;x-y&quot; where <code>x</code> is the start value, and <code>y</code> is the end value,</li>
 * <li> &quot;x,y,z,etc&quot; where <code>x,y,z,etc</code> are separate values, each one after another, or</li>
 * <li> &quot;x&quot; where <code>x</code> is a single occurance during the time specified to run.
 * <p/>
 * If a range is given in the format &quot;x-y&quot;, the number will equal to or between the start and end values.  A value
 * of &quot;0-59&quot; in the seconds columnn will force the item to be run every second.
 * <p/>
 * Keep in mind that when you run these schedules, you should run the schedule as efficiently as possible.  Running a scheduled
 * item every second can lead to inefficient code, and an inefficient server.  It is not recommended to run scheduled tasks
 * every second unless there is a critical portion of code that needs to be executed.
 *
 * @author Kenji Hollis &lt;kenji@bitgatesoftware.com&gt;
 * @since 0.1
 */
public class SchedulerTimeContext
{
    /**
     * This constant, when used in a time area in the <code>SchedulerTimeContext</code>, indicates that the value should
     * not be used.
     */
    public final static String NO_TIMES = "*";
    private final String second, minute, hour, day, week, month;

    /**
     * Constructor indicating the time in which the task is to be used.
     *
     * @param second The second range in which to trigger the class.
     * @param minute The minute range in which to trigger the class.
     * @param hour The hour range in which to trigger the class.
     * @param day The day range in which to trigger the class.
     * @param week The week range in which to trigger the class.
     * @param month The month range in which to trigger the class.
     */
    public SchedulerTimeContext(String second, String minute, String hour, String day, String week, String month)
    {
    	if (second == null || "".equals(second)) {
		    this.second = NO_TIMES;
		} else {
			this.second = second;
		}
	
		if (minute == null || "".equals(minute)) {
		    this.minute = NO_TIMES;
		} else {
			this.minute = minute;
		}
	
		if (hour == null || "".equals(hour)) {
		    this.hour = NO_TIMES;
		} else {
			this.hour = hour;
		}
	
		if (day == null || "".equals(day)) {
		    this.day = NO_TIMES;
		} else {
			this.day = day;
		}
	
		if (week == null || "".equals(week)) {
		    this.week = NO_TIMES;
		} else {
			this.week = week;
		}
	
		if (month == null || "".equals(month)) {
		    this.month = NO_TIMES;
		} else {
			this.month = month;
		}
    }

    /**
     * Returns the second range in which this class is triggered.
     *
     * @return <code>String</code> containing the range.
     */
    public String getSeconds()
    {
    	return this.second;
    }

    /**
     * Returns the minute range in which this class is triggered.
     *
     * @return <code>String</code> containing the range.
     */
    public String getMinutes()
    {
    	return this.minute;
    }

    /**
     * Returns the hour range in which this class is triggered.
     *
     * @return <code>String</code> containing the range.
     */
    public String getHours()
    {
    	return this.hour;
    }

    /**
     * Returns the day range in which this class is triggered.
     *
     * @return <code>String</code> containing the range.
     */
    public String getDays()
    {
    	return this.day;
    }

    /**
     * Returns the week range in which this class is triggered.
     *
     * @return <code>String</code> containing the range.
     */
    public String getWeeks()
    {
    	return this.week;
    }

    /**
     * Returns the month range in which this class is triggered.
     *
     * @return <code>String</code> containing the range.
     */
    public String getMonths()
    {
    	return this.month;
    }
}
